package sicnu.cs.aps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import sicnu.cs.aps.common.enums.ActivitySignEnum;
import sicnu.cs.aps.domain.entity.ActivityTeamFeedback;
import sicnu.cs.aps.domain.form.ActivityTeamFeedbackForm;
import sicnu.cs.aps.domain.vo.TimeEventVo;
import sicnu.cs.aps.mapper.ActivityTeamFeedbackMapper;
import sicnu.cs.aps.service.IActivityTeamFeedbackService;

import java.util.List;
import java.util.Optional;

/**
 * @author chengke
 * @version 1.0
 * @className ActivityTeamFeedbackServiceImpl
 * @description 活动反馈实现类
 * @date 2022/6/1 15:11
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ActivityTeamFeedbackServiceImpl extends ServiceImpl<ActivityTeamFeedbackMapper,ActivityTeamFeedback> implements IActivityTeamFeedbackService {

    private final ActivityTeamFeedbackMapper teamFeedbackMapper;

    @Override
    public PageInfo<ActivityTeamFeedback> selectBlogList(ActivityTeamFeedbackForm activityTeamFeedbackForm) {
        PageHelper.startPage(activityTeamFeedbackForm.getPageNum(),activityTeamFeedbackForm.getPageSize());
        List<ActivityTeamFeedback> activityTeamFeedbackList;
        if (activityTeamFeedbackForm.getKeyword() == null){
            activityTeamFeedbackList = teamFeedbackMapper.selectBlogList(activityTeamFeedbackForm.getCollegeId(), activityTeamFeedbackForm.getKeyword());
        }else {
            activityTeamFeedbackList = teamFeedbackMapper.selectBlogList(activityTeamFeedbackForm.getCollegeId(), activityTeamFeedbackForm.getKeyword().trim());
        }
        return new PageInfo<>(activityTeamFeedbackList);
    }
    /**
     * 通过反馈查询活动反馈时间点事件信息
     *
     * @param teamId 队伍id
     * @return 队伍的反馈时间
     */
    @Override
    public TimeEventVo getTeamCompleteTimeLine(Long teamId) {
        //TODO 完成逻辑
        ActivityTeamFeedback activityTeamFeedback = teamFeedbackMapper.selectById(teamId);
        if (activityTeamFeedback == null){
            return null;
        }
        return TimeEventVo.builder().opTime(activityTeamFeedback.getLastEditDate())
                .opEvent(ActivitySignEnum.ACTIVITY_WAIT_FOR_FEEDBACK)
                .opDesc("完成反馈")
                .operatorName(activityTeamFeedback.getAuthor()).build();
    }
}